{include 'admin/layout/header_list'}
<link rel="stylesheet" href="__ADMIN_STATIC__/css/addContent.css?random={extendSetting('random')}">
<link rel="stylesheet" href="__ADMIN_STATIC__/css/content.css?random={extendSetting('random')}">
<!-- js文件 -->
<script src="__ADMIN_STATIC__/js/lib/eletree/eleTree.js?random={extendSetting('random')}"></script>
<!-- 加载字体文件样式 -->
<link rel="stylesheet" href="__ADMIN_STATIC__/js/lib/eletree/css/icon.css?random={extendSetting('random')}"></script>
<div class="addcontent">
    <form class="ajaxForm" method="post">
        <input type="hidden" name="_method" value="put">
        <input type="hidden" name="roleId" value="{if isset($info['id'])}{$info['id']}{/if}">
        <table class="table">
            <tr>
                <td class="tl">
                    <span><strong>* </strong>id</span>
                </td>
                <td>
                    <input class="long" type="text" value="{$info?$info['id']:''}" disabled>
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span><strong>* </strong>角色名称</span>
                </td>
                <td>
                    <input class="long" type="text" name="name" value="{$info?$info['name']:''}" disabled>
                </td>
            </tr>
            <tr>
                <td class="tl">
                    <span>选择绑定功能</span>
                </td>
                <td>
                    <div class="eletree"></div>
                </td>
            </tr>

        </table>
    </form>
    <div class="ltcms-button">
        <button class="btns submit ajaxBtn" onclick="dataMoreRoleBindFunc(this)" data-submit-url="" data-method="put"
                data-close="5" data-roleId="{$info['id']}">
            确认保存
        </button>
         <button class="btns cancel">取消并返回</button>
    </div>
</div>
<script src="__ADMIN_STATIC__/js/addContent.js?random={extendSetting('random')}"></script>
<script src="__ADMIN_STATIC__/js/list.js?random={extendSetting('random')}"></script>
<script>
    let data={$menuJson};
    //https://eletree.hsianglee.cn/eleTree/usedocs-methods.html  组件来源
    var ele = eleTree({
        el: '.eletree',
        data: data,
        showCheckbox: true,
        highlightCurrent: true,
        showRadio: false,

    })


    function eleSetChecked() {
        ele.setChecked([{$roleFuncList}]); // 勾选对应 id 值的节点
    }
    eleSetChecked() //初始化勾选数据

    function getChecked() {
        var checkedData =  ele.getChecked(true, false, false); // 勾选对应 id 值的节点
        layer.alert(JSON.stringify(checkedData), {shade:0});
    }


    /*
     批量角色绑定功能
     */
    function dataMoreRoleBindFunc(obj) {

        let jsonData=ele.getChecked(true, false, false); // 勾选对应 id 值的节点
        // Extract and print "id" values3
        let ids=  jsonData.map(function(member) {
            return member.id;
        });

        ids = ids.join(',');

        let msgIndex = layer.msg('正在保存', {
            icon: 16,
            shade: 0.05,
            time:60000
        });
        $.post("{LTCMS_ROUTE_PREFIX}/adminRoleFunc/setRoleBindFunc",{"roleId":$("input[name='roleId']").val(), "id": ids, "_method": "put"}, function(json){   // 从服务端异步获取json并执行函数
            layer.close(msgIndex)
            if (json.success){
                layer.msg(json.codeMsg, {icon: 1, time: 1000});
                history.back();
            }else {
                layer.msg(json.codeMsg, {icon: 2, time: 1000});
            }
        });


    }



</script>
{include 'admin/layout/footer'}